package com.huluobo.a2302mdmdemo.demo

import android.util.Log
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AccountCircle
import androidx.compose.material.icons.filled.Lock
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp

/**
 *  Created by LC on 2025/7/18.
 */

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MyEdit() {
    //带状态的变量
//    var name = ""
    var name by remember {
        //可变的状态
        mutableStateOf("")
    }

    var pass by remember {
        mutableStateOf("")
    }

    var isShowPassword by remember {
        mutableStateOf(false)
    }

    Column(Modifier.padding(10.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
        TextField(value = name, onValueChange = {
            //当内容输入的时候,it就是输入的内容,来给name赋值
            name = it
        },
            //标签
            label = {
                Text(text = "请输入用户名")
            }, modifier = Modifier.fillMaxWidth(),
            //左侧图标
            leadingIcon = {
                Icon(imageVector = Icons.Default.AccountCircle, contentDescription = "")
            },
            //右侧图标
            trailingIcon = {
                Icon(imageVector = Icons.Default.AccountCircle, contentDescription = "")
            }
        )

        TextField(
            value = pass, onValueChange = {
                //当内容输入的时候,it就是输入的内容,来给name赋值
                pass = it
            },
            //标签
            label = {
                Text(text = "请输入密码")
            },
            modifier = Modifier.fillMaxWidth(),
            leadingIcon = {
                Icon(imageVector = Icons.Default.Lock, contentDescription = "")
            },
            trailingIcon = {
                Icon(imageVector = Icons.Default.Lock, contentDescription = "", modifier = Modifier.clickable {
                    isShowPassword = !isShowPassword
                })
            },
            //是否显示明文密文
            visualTransformation = if (isShowPassword) VisualTransformation.None else PasswordVisualTransformation(),
            colors = TextFieldDefaults.textFieldColors(
                containerColor = Color.White,
                focusedIndicatorColor = Color.White,
                unfocusedIndicatorColor = Color.White
            )
        )

        //带边框的输入框样式
        OutlinedTextField(value = name, onValueChange = {
            name = it
        }, label = {
            Text(text = "请输入密码")
        })
    }
}